package com.hks360.library.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {

    public static final String PHONE = "^((\\+86)|(86))?(1)\\d{10}$";
    public static final String EMAIL = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$";
    public static final String USERNAME = "^[a-zA-Z][a-zA-Z0-9_-]{2,15}$";
    public static final String PASSWD = "^.{6,18}$";
    public static final String LICENSENO = "^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
    
    public static boolean checkPhone(String str) {
        return checkStr(PHONE, str);
    }

    public static boolean checkEmail(String str) {
        return checkStr(EMAIL, str);
    }

    public static boolean checkUsername(String str) {
        return checkStr(USERNAME, str);
    }

    public static boolean checkPasswd(String str) {
        return checkStr(PASSWD, str);
    }
    
    public static boolean checkLicenseno(String str) {
    	return checkStr(LICENSENO, str);
    }

    public static boolean checkStr(String pattern, String input) {
        if (StringUtil.isEmpty(input)) {
            return false;
        }
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(input);
        return m.matches();
    }
}
